class Solution(object):
    def __init__(self):
        self.table = {}

    def myPow(self, x, n):
        if n == 0:
            return 1
        elif n == -1:
            return 1 / x
        elif n == 1:
            return x
        elif str(x) + '_' + str(n) in self.table:
            return self.table[str(x) + '_' + str(n)]
        mid = n // 2
        self.table[str(x) + '_' + str(mid)] = self.myPow(x, mid)
        self.table[str(x) + '_' + str(n - mid)] = self.myPow(x, n - mid)
        res = self.table[str(x) + '_' + str(mid)] * self.table[str(x) + '_' + str(n - mid)]
        return res


print(Solution().myPow(2, 10))
print(Solution().myPow(2.1, 3))
print(Solution().myPow(2, -2))
